<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Returns a subset of the map defined by a starting index and length</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="ds-map.skip.html">« Ds\Map::skip</a></li>
      <li style="float: right;"><a href="ds-map.sort.html">Ds\Map::sort »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.ds-map.html">Map</a></li>
    <li>Returns a subset of the map defined by a starting index and length</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="ds-map.slice" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">Ds\Map::slice</h1>
  <p class="verinfo">(PECL ds &gt;= 1.0.0)</p><p class="refpurpose"><span class="refname">Ds\Map::slice</span> &mdash; <span class="dc-title">
   Returns a subset of the map defined by a starting index and length
  </span></p>

 </div>

 <div class="refsect1 description" id="refsect1-ds-map.slice-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>Ds\Map::slice</strong></span>(<span class="methodparam"><span class="type">int</span> <code class="parameter">$index</code></span>, <span class="methodparam"><span class="type">int</span> <code class="parameter">$length</code><span class="initializer"> = ?</span></span>): <span class="type"><a href="class.ds-map.html" class="type Ds\Map">Ds\Map</a></span></div>

  <p class="para rdfs-comment">
    Returns a subset of the map defined by a starting <code class="parameter">index</code> and <code class="parameter">length</code>.
  </p>

 </div>


 <div class="refsect1 parameters" id="refsect1-ds-map.slice-parameters">
  <h3 class="title">参数</h3>
  <dl>
   
    <dt>
<code class="parameter">index</code></dt>

    <dd>

        <p class="para">
            The index at which the range starts.
        </p>
        <p class="para">
            If positive, the range will start at that index in the map.
            If negative, the range will start that far from the end.
        </p>
    </dd>

    
    
    <dt>
<code class="parameter">length</code></dt>

    <dd>

     <p class="para">
        If a length is given and is positive, the resulting
        map will have up to that many pairs in it.

        If a length is given and is negative, the range
        will stop that many pairs from the end.

        If the length results in an overflow, only
        pairs up to the end of the map will be included.

        If a length is not provided, the resulting map
        will contain all pairs between the index and the
        end of the map.
     </p>
    </dd>

   
  </dl>

 </div>


 <div class="refsect1 returnvalues" id="refsect1-ds-map.slice-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
    A subset of the map defined by a starting index and length.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-ds-map.slice-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="example-4107">
   <p><strong>示例 #1 <span class="function"><strong>Ds\Map::slice()</strong></span> example</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$map&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;\</span><span style="color: #0000BB">Ds</span><span style="color: #007700">\</span><span style="color: #0000BB">Map</span><span style="color: #007700">([</span><span style="color: #DD0000">"a"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"b"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">2</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"c"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">3</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"d"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">4</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"e"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">5</span><span style="color: #007700">]);<br /><br /></span><span style="color: #FF8000">//&nbsp;Slice&nbsp;from&nbsp;2&nbsp;onwards<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$map</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">slice</span><span style="color: #007700">(</span><span style="color: #0000BB">2</span><span style="color: #007700">)-&gt;</span><span style="color: #0000BB">toArray</span><span style="color: #007700">());<br /><br /></span><span style="color: #FF8000">//&nbsp;Slice&nbsp;from&nbsp;1,&nbsp;for&nbsp;a&nbsp;length&nbsp;of&nbsp;3<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$map</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">slice</span><span style="color: #007700">(</span><span style="color: #0000BB">1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">3</span><span style="color: #007700">)-&gt;</span><span style="color: #0000BB">toArray</span><span style="color: #007700">());<br /><br /></span><span style="color: #FF8000">//&nbsp;Slice&nbsp;from&nbsp;1&nbsp;onwards<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$map</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">slice</span><span style="color: #007700">(</span><span style="color: #0000BB">1</span><span style="color: #007700">)-&gt;</span><span style="color: #0000BB">toArray</span><span style="color: #007700">());<br /><br /></span><span style="color: #FF8000">//&nbsp;Slice&nbsp;from&nbsp;2&nbsp;from&nbsp;the&nbsp;end&nbsp;onwards<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$map</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">slice</span><span style="color: #007700">(-</span><span style="color: #0000BB">2</span><span style="color: #007700">)-&gt;</span><span style="color: #0000BB">toArray</span><span style="color: #007700">());<br /><br /></span><span style="color: #FF8000">//&nbsp;Slice&nbsp;from&nbsp;1&nbsp;to&nbsp;1&nbsp;from&nbsp;the&nbsp;end<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$map</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">slice</span><span style="color: #007700">(</span><span style="color: #0000BB">1</span><span style="color: #007700">,&nbsp;-</span><span style="color: #0000BB">1</span><span style="color: #007700">)-&gt;</span><span style="color: #0000BB">toArray</span><span style="color: #007700">());<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   <div class="example-contents"><p>以上例程的输出类似于：</p></div>
   <div class="example-contents screen">
<div class="cdata"><pre>
Array
(
    [c] =&gt; 3
    [d] =&gt; 4
    [e] =&gt; 5
)
Array
(
    [b] =&gt; 2
    [c] =&gt; 3
    [d] =&gt; 4
)
Array
(
    [b] =&gt; 2
    [c] =&gt; 3
    [d] =&gt; 4
    [e] =&gt; 5
)
Array
(
    [d] =&gt; 4
    [e] =&gt; 5
)
Array
(
    [b] =&gt; 2
    [c] =&gt; 3
    [d] =&gt; 4
)
</pre></div>
   </div>
  </div>
 </div>



</div></div></div></body></html>